using System;
using System.Configuration;

namespace Impact.Infrastructure.Configuration
{

    /// <summary>
    /// a collection of plugins that can be configured for use in the system
    /// </summary>
    public class PluginSettingsCollection : System.Configuration.ConfigurationElementCollection
    {

        /// <summary>
        /// default constructor
        /// </summary>
        public PluginSettingsCollection()
        {
        }

        /// <summary>
        /// indexer to retrieve a plugin by index
        /// </summary>
        public PluginSettings this[int index]
        {
            get { return ((PluginSettings)base.BaseGet(index)); }
        }

        /// <summary>
        /// creates a new element for use in the collection
        /// </summary>
        protected override ConfigurationElement CreateNewElement()
        {
            return new PluginSettings();
        }

        /// <summary>
        /// retrieves the key of the element that is represented by the parameter
        /// </summary>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return (element as PluginSettings).Type;
        }
    }

    /// <summary>
    /// this class is a container for the data used to load a single plugin
    /// </summary>
    public class PluginSettings : System.Configuration.ConfigurationElement
    {
        /// <summary>
        /// default constructor
        /// </summary>
        public PluginSettings()
        {
        }

        /// <summary>
        /// the type of the plugin to load in the form of "Classname, Assembly"
        /// </summary>
        [ConfigurationProperty("type")]
        public string Type
        {
            get { return (string)this["type"]; }
            set { this["type"] = value; }
        }

    }
}
